/**
 * Copyright(c) kyle.
 */
package org.example.plugin_annotation_processor;

import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import java.util.Set;

/**
 * 注解处理器
 *
 * @author kyle
 * @version 1.00.00
 * @since [2020-12-05 23:53]
 * @updateUser [Kyle]
 * @updateRemark [说明本次修改内容]
 * @date [2020-12-05 23:53]
 */
@SupportedAnnotationTypes("*")//*表示支持所有的Annotations
@SupportedSourceVersion(SourceVersion.RELEASE_8)//只支持JDK 8的代码
public class NameCheckProcessor extends AbstractProcessor {
    private NameChecker nameChecker;

    /**
     * 初始化名称检查插件
     *
     * @param processingEnv
     */
    @Override
    public synchronized void init(ProcessingEnvironment processingEnv) {
        super.init(processingEnv);
        nameChecker = new NameChecker(processingEnv);
    }

    /**
     * 对输入的语法树的各个节点进行名称检查
     *
     * @param annotations
     * @param roundEnv
     * @return
     */
    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        if (!roundEnv.processingOver()) {
            for (Element element :
                    roundEnv.getRootElements()) {
                nameChecker.checkNames(element);
            }
        }
        return false;
    }
}
